import { Button, Input, Modal } from 'antd'
import React, { useState } from 'react'
import { QRCodeCanvas } from 'qrcode.react';
import { useQRCodeModalNDow } from '@/store/adapter/useGlobalStatus';
import Wrapper from './Wrapper';
const QRCodeNDow = () => {
    const { qrcodeMobalNDow, closeQrcodeMobalNDow } = useQRCodeModalNDow()
    const changeCanvasToPic = () => {
        const canvasImg = document.getElementById('qrCode') as HTMLCanvasElement; // 获取canvas类型的二维码
        const img = new Image();
        img.src = canvasImg.toDataURL('image/png'); // 将canvas对象转换为图片的data url
        // 获取文件对象
        const ImageFile = dataURLtoFile(img.src, "二维码")
        console.log(ImageFile, 'ImageFile');

    };
    const dataURLtoFile = (dataurl: any, filename: any) => {
        var arr = dataurl.split(','),
            mime = arr[0].match(/:(.*?);/)[1],
            bstr = atob(arr[1]),
            n = bstr.length,
            u8arr = new Uint8Array(n);

        while (n--) {
            u8arr[n] = bstr.charCodeAt(n);
        }
        return new File([u8arr], filename, { type: mime });
    }
    return (
        <Modal
            title="生成二维码"
            footer={false}
            open={qrcodeMobalNDow}
            width={713}
            centered={true}
            onCancel={closeQrcodeMobalNDow}
            getContainer={document.getElementById('oneRoot') as HTMLElement}

        >
            <Wrapper />
        </Modal>
    )
}

export default QRCodeNDow